package com.wengyingjian.weixin.dao;

import com.wengyingjian.weixin.common.model.WxRequestRecord;
import com.wengyingjian.weixin.dao.mapper.WxRequestRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;

/**
 * Created by hzwengyingjian on 16/12/27.
 */
@Repository
public class WxRequestRecordDao {
    @Autowired
    private WxRequestRecordMapper masterWxRequestRecordMapper;

    public WxRequestRecord selectByMsgId(String msgId) {
        return masterWxRequestRecordMapper.selectByMsgId(msgId);
    }

    public void updateByMsgId(WxRequestRecord update) {
        masterWxRequestRecordMapper.updateByMsgId(update);
    }

    public void insert(WxRequestRecord insert) {
        if (insert.getContent() != null && insert.getContent().length() > 500) {
            insert.setContent(insert.getContent().substring(0, 500));
        }
        insert.setCreateTime(new Timestamp(System.currentTimeMillis()));
        masterWxRequestRecordMapper.insertSelective(insert);
    }

    public void addRepeatCountById(Long id) {
        masterWxRequestRecordMapper.addRepeatCountById(id);
    }
}
